package com.eudon.design_pattern.creational.builder;

import com.eudon.design_pattern.creational.abstract_factory.storage.Storage;
import com.eudon.design_pattern.creational.builder.component.Charger;
import com.eudon.design_pattern.creational.builder.component.Color;
import com.eudon.design_pattern.creational.builder.component.Cpu;
import com.eudon.design_pattern.creational.builder.component.memory.Memory;

/**
 * @author eudon
 * @description 手机
 * @date 2025/9/1
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class Phone {
    private final String name = "xiaomi 16 pro";
    private Memory memory;
    private Storage storage;
    private Color color;
    private Charger charger;
    private Cpu cpu;

    private Phone(){
    }

    public static PhoneBuilder builder(){
        return new PhoneBuilder(new Phone());
    }
    public static class PhoneBuilder{
        private final Phone phone;

        public PhoneBuilder(Phone phone) {
            this.phone = phone;
        }

        PhoneBuilder withMemory(Memory memory){
            this.phone.memory = memory;
            return this;
        }
        PhoneBuilder withStorage(Storage storage){
            this.phone.storage = storage;
            return this;
        }
        PhoneBuilder withColor(Color color){
            this.phone.color = color;
            return this;
        }
        PhoneBuilder withCharger(Charger charger){
            this.phone.charger = charger;
            return this;
        }
        PhoneBuilder withCpu(Cpu cpu){
            this.phone.cpu = cpu;
            return this;
        }
        public Phone build(){
            return this.phone;
        }
    }

    public String toString(){
        return "该xiaomi 16 pro的配置：" +
                "cpu:"+ cpu.name()+
                "内存:"+ memory.getInfo()+
                "储存空间:"+ storage.getInfo()+
                "充电功率:"+ charger.name()+
                "颜色:"+ color.name();
    }
}
